package lambda;

/**
 * lambda演化史
 *
 */
public class Test1 {
    public static void main(String[] args) {
        // 2. 外部实现类
        ILike like1 = new Like1();
        like1.lambda();

        // 3. 静态内部类
        ILike like2 = new Like2();
        like2.lambda();

        // 4. 局部内部类
        class Like3 implements ILike {
            @Override
            public void lambda() {
                System.out.println("Local class likes lambda");
            }
        }
        ILike like3 = new Like3();
        like3.lambda();

        // 5. 匿名内部类
        ILike like4 = new ILike(){
            @Override
            public void lambda()  {
                System.out.println("anonymous inner class likes lambda");
            }
        };
        like4.lambda();

        // 6. lambda简化
        ILike like5 = ()->{System.out.println("anonymous inner class likes lambda");};
        ILike like6 = ()->System.out.println("anonymous inner class likes lambda");  // 去掉花括号
        ILike1 iLike1 = a ->System.out.println("anonymous inner class likes lambda"+a);  // 传参数
        ILike2 iLike2 = (a,b) ->System.out.println("anonymous inner class likes lambda"+a+b);  // 多参
        like5.lambda();
        like6.lambda();
        iLike1.lambda(1);
        iLike2.lambda(1,2);

    }

    // 静态内部类
    static class Like2 implements ILike{
        @Override
        public void lambda() {
            System.out.println("static class like lambda");
        }
    }


}

// 1.定义一个函数式接口
interface ILike{
    void lambda();
}
interface ILike1{
    void lambda(int e);
}
interface ILike2{
    void lambda(int a, int b);
}

// 外部实现类
class Like1 implements ILike{
    @Override
    public void lambda() {
        System.out.println("out class like lambda");
    }
}
